﻿//----------------------------------------------------

#region 命名空间

//    版权：
//    作者：
//建立时间：2012-09-11 00:00:33
//    描述：
//----------------------------------------------------
using System;
using System.Data;
using System.Text;
using System.Web.UI;
using System.Web.UI.WebControls;
using WinnerCMS.Data;
using System.Collections.Generic;
using WinnerCMS.Model;
using WinnerCMS.Common;

#endregion

namespace WinnerCMS.BLL
{
    /// <summary>
    /// 业务逻辑类 WinnerCMS_Help 的摘要说明。
    /// </summary>
    public class HelpManage
    {
        private static readonly HelpDal MyDAL = new HelpDal();

        #region 添加

        /// <summary>
        /// 添加
        /// </summary>
        public Result Add(Help model)
        {
            Result resu = new Result();
            if (model.Title.Length == 0)
            {
                resu.Errors = "“标题”不能为空！";
                return resu;
            }
            if (model.Content.Length == 0)
            {
                resu.Errors = "“内容”不能为空！";
                return resu;
            }
            if (model.Admin.Length == 0)
            {
                resu.Errors = "“管理员”不能为空！";
                return resu;
            }

            if (model.Id == 0)
            {
                MyDAL.Add(model);

                Log logModel = new Log();
                logModel.Type = "帮助管理";
                logModel.Event = "添加帮助：" + model.Title;
                LogManage.Add(logModel);
            }
            else
            {
                MyDAL.Edit(model);

                Log logModel = new Log();
                logModel.Type = "帮助管理";
                logModel.Event = "修改帮助ID：" + model.Id;
                LogManage.Add(logModel);
            }
            return resu;
        }

        #endregion

        #region 删除

        /// <summary>
        /// 删除
        /// </summary>
        public void Delete(string IDs, UpdatePanel UpdatePanel1)
        {
            if (string.IsNullOrEmpty(IDs))
            {
                MsgBox.Message("至少选择一项。", UpdatePanel1);
            }
            else
            {
                MyDAL.Delete(MyConvert.ConvertToArr(IDs));

                Log logModel = new Log();
                logModel.Type = "帮助管理";
                logModel.Event = "批量帮助公告ID：" + IDs;
                LogManage.Add(logModel);

                MsgBox.Message("删除成功！", UpdatePanel1);
            }
        }

        #endregion

        /// <summary>
        /// 审核或者取消审核
        /// </summary>
        /// <param name="id"></param>
        public void PassOrNo(string id)
        {
            bool state = MyDAL.PassOrNo(int.Parse(id));

            if (state)
            {
                Log logModel = new Log();
                logModel.Type = "帮助管理";
                logModel.Event = "通过审核ID" + id;
                LogManage.Add(logModel);
            }
            else
            {
                Log logModel = new Log();
                logModel.Type = "帮助管理";
                logModel.Event = "撤消审核ID" + id;
                LogManage.Add(logModel);
            }
        }

        #region 加载数据

        /// <summary>
        /// 加载数据
        /// </summary>
        public Help GetInfo(int ID)
        {
            return MyDAL.GetInfo(ID);
        }

        #endregion

        /// <summary>
        /// 绑定数据
        /// </summary>
        /// <param name="pp"></param>
        /// <returns></returns>
        public IList<Help> BindList(PagingParam pp)
        {
            return MyDAL.BindList(pp);
        }
    }
}